package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jsola.core.example.BaseExample.*;
import static org.jsola.hr.example.AttendPunchRecordExample.*;

/**
 * 考勤打卡记录
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class AttendPunchRecordQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_COMPANY_NAME, example = E_COMPANY_NAME)
    @Length(max = 100)
    private String companyName;

    @ApiParam(value = N_DEPT_ID, example = E_DEPT_ID)
    @Length(max = 32)
    private String deptId;

    @ApiParam(value = N_DEPT_NAME, example = E_DEPT_NAME)
    @Length(max = 100)
    private String deptName;

    @ApiParam(value = N_EMP_INFO_ID, example = E_EMP_INFO_ID)
    @Length(max = 32)
    private String empInfoId;

    @ApiParam(value = N_EMP_INFO_NAME, example = E_EMP_INFO_NAME)
    @Length(max = 50)
    private String empInfoName;

    @ApiParam(value = N_ATTEND_PLAN_ID, example = E_ATTEND_PLAN_ID)
    @Length(max = 32)
    private String attendPlanId;

    @ApiParam(value = N_ATTEND_PLAN_NAME, example = E_ATTEND_PLAN_NAME)
    @Length(max = 100)
    private String attendPlanName;

    @ApiParam(value = N_YEAR, example = E_YEAR)
    @Length(max = 10)
    private String year;

    @ApiParam(value = N_MONTH, example = E_MONTH)
    @Length(max = 10)
    private String month;

    @ApiParam(value = N_DAY, example = E_DAY)
    @Length(max = 10)
    private String day;

    @ApiParam(value = N_PUNCH_TYPE, example = E_PUNCH_TYPE)
    private Integer punchType;

    @ApiParam(value = N_PUNCH_RANGE, example = E_PUNCH_RANGE)
    private Integer punchRange;

    @ApiParam(value = N_STANDARD_TIME, example = E_STANDARD_TIME)
    private Date standardTime;

    @ApiParam(value = "打卡时间点", example = "")
    private List<String> standardTimeLst;

    @ApiParam(value = N_PUNCH_TIME, example = E_PUNCH_TIME)
    private Date punchTime;

    @ApiParam(value = N_PUNCH_STATUS, example = E_PUNCH_STATUS)
    private Integer punchStatus;

    @ApiParam(value = "打卡状态不等于", example = "")
    private Integer NotEqPunchStatus;

    @ApiParam(value = N_MINUTE, example = E_MINUTE)
    private Integer minute;

    @ApiParam(value = N_WORK_TIME, example = E_WORK_TIME)
    private Integer workTime;

    @ApiParam(value = N_DECISION_DESC, example = E_DECISION_DESC)
    @Length(max = 255)
    private String decisionDesc;

    @ApiParam(value = N_COORDINATE, example = E_COORDINATE)
    @Length(max = 255)
    private String coordinate;

    @ApiParam(value = N_LOCATION, example = E_LOCATION)
    @Length(max = 255)
    private String location;

    @ApiParam(value = N_PUNCH_WIFI, example = E_PUNCH_WIFI)
    @Length(max = 255)
    private String punchWifi;

    @ApiParam(value = N_PUNCH_SOURCE, example = E_PUNCH_SOURCE)
    private Integer punchSource;

    @ApiParam(value = N_IS_CALIBRATION, example = E_IS_CALIBRATION)
    private Boolean isCalibration;

    @ApiParam(value = N_IS_MAKE_UP, example = E_IS_MAKE_UP)
    private Boolean isMakeUp;

    @ApiParam(value = N_HIS_STANDARD_TIME, example = E_HIS_STANDARD_TIME)
    @Length(max = 32)
    private String hisStandardTime;

    @ApiParam(value = N_HIS_PUNCH_TIME, example = E_HIS_PUNCH_TIME)
    private Date hisPunchTime;

    @ApiParam(value = N_HIS_PUNCH_STATUS, example = E_HIS_PUNCH_STATUS)
    private Integer hisPunchStatus;

    @ApiParam(value = N_PUNCH_SERIAL, example = E_PUNCH_SERIAL)
    @Length(max = 32)
    private String punchSerial;

    @ApiParam(value = N_POSITION_ID, example = E_POSITION_ID)
    private String positionId;

    @ApiParam(value = N_EMP_INFO_ID_LIST, example = E_EMP_INFO_ID_LIST)
    private List<String> empInfoIdList;

    @ApiParam(value = "是否只导出异常数据")
    private Boolean isError;

    @ApiParam(value = "查询开始时间字符串，格式：yyyyMMdd")
    private String startTime;

    @ApiParam(value = "查询结束时间字符串，格式：yyyyMMdd")
    private String endTime;

    /**
     * 打卡日期时间查询范围
     */
    @ApiParam(value = "打卡日期起始时间: 格式：yyyy-MM-dd")
    private String attendStart;
    @ApiParam(value = "打卡日期结束时间 格式：yyyy-MM-dd")
    private String attendEnd;

    @ApiParam(value = "岗位id")
    private String positionInfoId;

    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public AttendPunchRecordQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

